﻿using Ssdb.Provider;
using System;
using System.Collections.Generic;
using System.Text;

namespace RedisDemo
{
    internal class Program
    {
        private static readonly SsdbClient Client = SsdbClient.GetClient("127.0.0.1", 8888);

        private static void Main(string[] args)
        {
            string str = "这是一个测试数据";
            string key = "testkey";
            Console.WriteLine(Client.Add(key, str));
            Console.WriteLine(Client.Get<string>(key));
            string key2 = "testkey2";
            Console.WriteLine(Client.Add(key2, new MyClass
            {
                Id = 0,
                Name = "test"
            }));
            var result = Client.Get<MyClass>(key2);
            Console.WriteLine("aaa");
            Console.ReadLine();
        }

        private static void Main2(string[] args)
        {
            List<byte[]> resp = Client.Request("set", "a", "100");
            foreach (byte[] bs in resp)
            {
                Console.WriteLine(Encoding.Default.GetString(bs));
            }

            resp = Client.Request("get", "a");
            foreach (byte[] bs in resp)
            {
                Console.WriteLine(Encoding.Default.GetString(bs));
            }

            Client.Set("a", "99");
            string val;
            Client.Get("a", out val);
            Console.WriteLine(val);

            Console.WriteLine("-----------------");
            {
                KeyValuePair<string, byte[]>[] kvs = Client.Scan("", "", 3);
                Console.WriteLine(kvs.Length + " kvs");
                foreach (KeyValuePair<string, byte[]> kv in kvs)
                {
                    Console.WriteLine("    " + kv.Key + ": " + Encoding.Default.GetString(kv.Value));
                }
            }
            Console.WriteLine("-----------------");
            {
                KeyValuePair<string, long>[] kvs = Client.Zscan("z", "", long.MinValue, long.MaxValue, 3);
                Console.WriteLine(kvs.Length + " kvs");
                foreach (KeyValuePair<string, long> kv in kvs)
                {
                    Console.WriteLine("    " + kv.Key + ": " + kv.Value);
                }
            }
            Console.WriteLine("-----------------");
            {
                KeyValuePair<string, long>[] kvs = Client.Zrscan("z", "", long.MaxValue, long.MinValue, 3);
                Console.WriteLine(kvs.Length + " kvs");
                foreach (KeyValuePair<string, long> kv in kvs)
                {
                    Console.WriteLine("    " + kv.Key + ": " + kv.Value);
                }
            }

            Console.WriteLine(Client.Zsize("z").ToString());

            Console.ReadLine();
        }

        #region Nested type: MyClass

        private class MyClass
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }

        #endregion Nested type: MyClass
    }
}